package com.baimuzhi.newcreate;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.Properties;

/**
 * @author: Zxeao
 * @description 代码生成器
 * @date: 2023/1/17 19:52
 */
@SpringBootTest
public class Generator {
    public static void main(String[] args) throws IOException {
        //配置文件路径
        InputStream inputStream = new FileInputStream("F:\\desktop\\desktop\\baimuzhi\\baimuzhi-agricultural-platform\\back\\user\\src\\main\\resources\\application.properties");
        Properties ps = new Properties();
        ps.load(inputStream);
        //加载数据库用户名和密码
        String username = ps.getProperty("spring.datasource.username");
        String password = ps.getProperty("spring.datasource.password");
        String url = ps.getProperty("spring.datasource.url");

        FastAutoGenerator.create(url,username,password)
                .globalConfig(builder -> {
                    //作者
                    builder.author("肖叶茂")
                            //是否开启swagger
//                            .enableSwagger()
                            //是否重写文件
                            .fileOverride()
                            //输出文件路径
                            .outputDir("F:\\desktop\\desktop\\baimuzhi\\baimuzhi-agricultural-platform\\back\\user\\src\\main\\java");
                })
                .packageConfig(builder -> {
                    //组织名
                    builder.parent("com.baimuzhi.co")
                            //模块名
                            .moduleName("im")
                            //输出的mapper路径
                            .pathInfo(Collections.singletonMap(OutputFile.xml, "F:\\desktop\\desktop\\baimuzhi\\baimuzhi-agricultural-platform\\back\\user\\src\\main\\java\\com\\baimuzhi\\user\\mapper"));
                })
                .strategyConfig(builder -> {
                    //需要生成的表名
                    builder.addInclude("role,authority,authority_role,role_user,user");
                })
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();

    }
}
